package com.heima;

import com.alibaba.fastjson.JSON;
import com.heima.Mapper.ScearchMapper;
import com.heima.common.exception.ESCode;
import com.heima.model.Article.Pojo.ApArticleToES;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.util.List;

@SpringBootTest
public class esaddtest {

    @Autowired
    ScearchMapper scearchMapper;
//
//    @Autowired
//    RestHighLevelClient restHighLevelClient;
    @Test
    public void add() throws IOException {
//        scearchMapper.SelectToES(1302862387124125698L);
//        List<ApArticleToES> esList = scearchMapper.SelectListToES();
//        BulkRequest bulkRequest=new BulkRequest();
//        for(ApArticleToES article:esList)
//        {
//            bulkRequest.add(new IndexRequest(ESCode.IndexName).
//                    id(article.getId().toString()).
//                    source(JSON.toJSONString(article),XContentType.JSON));
//        }
//        restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
    }
}
